package com.company.IO;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;

public class MD5Class {
    public MD5Class() {
        String passwd = "MD5摘要算法测试";
        String salt = "Ramdom salt";
        byte[] r = new byte[0];
        try {
            r = MD5Class.toMD5((salt+passwd).getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        System.out.println(String.format("%032x",new BigInteger(1,r)));
    }

    public static byte[] toMD5(byte[] input) {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        md.update(input);
        return md.digest();
    }

//    public static void main(String[] args) throws Exception {
//        String passwd = "MD5摘要算法测试";
//        String salt = "Ramdom salt";
//        byte[] r = MD5Class.toMD5((salt+passwd).getBytes("UTF-8"));
//        System.out.println(String.format("%032x",new BigInteger(1,r)));
//    }
}
